// 构建路由
import {createRouter, createWebHistory} from 'vue-router'
import Layout from '@/layout/blog/index.vue'

// 2. 定义一些路由
// 每个路由都需要映射到一个组件。
// 我们后面再讨论嵌套路由。
const routes: any[] = [
    {
        path: '/login',
        name: 'login',
        component: () => import('@/views/login/index.vue'),
    },
    {
        path: '/',
        component: Layout,
        redirect: '/home',
        children: [
            {
                path: '/home',
                component: () => import('@/views/home/index.vue'),
                mate: {
                    title: '首页',
                }
            },
            {
                path: '/introduction',
                component: () =>  import('@/views/blog/introduction/index.vue'),
                name: 'introduction',
                meta: {
                    title: '博客介绍',
                    icon: 'el-icon-info',
                    keepAlive: true,
                }
            },
            {
                path: '/about',
                component: () => import('@/views/homeLayout/about/index.vue'),
            },
            {
                path: '/archives',
                component: () => import('@/views/archives/index.vue'),
                meta: {
                    title: '归档',
                    keepAlive: true,
                }
            },
            {
                path: '/search',
                component: () => import('@/views/search/index.vue'),
            },
            {
                path: '/diary',
                component: () => import('@/views/diary/index.vue'),
            },
            {
                path: '/user/setting',
                component: () => import('@/views/blog/user/setting/index.vue'),
                mate: {
                    title: '系统设置'
                }
            },
            {
                path: '/category',
                component: () => import('@/views/blog/category/index.vue'),
            },
            {
                path: '/article/edit/:artId',
                component: () => import('@/views/blog/article/edit/index.vue'),
            },
            {
                path: '/article/details/:artId',
                component:() =>  import('@/views/blog/article/details/index.vue'),
            },
            {
                path: '/article',
                component: () => import('@/views/blog/article/index.vue'),
                redirect: '/article/content',
                children: [
                    {
                        path: '/article/content',
                        component:() =>  import('@/views/blog/article/content/index.vue'),
                    },
                    {
                        path: '/article/category',
                        component: () => import('@/views/blog/article/category/index.vue'),
                    },
                    {
                        path: '/article/tags',
                        component: () => import('@/views/blog/article/tags/index.vue'),
                    }
                ]
            },
            {
                path: '/article/publish',
                component: () => import('@/views/blog/article/publish/index.vue'),
            }
        ],
    },
    {
        path: '/notebook',
        component: () => import('@/views/notebook/index.vue'),
    },

    /*匹配不到 404 页面*/
    {
        path: '/:pathMatch(.*)*',
        component: () => import('@/views/pages/404/index.vue'),
    },
]

const BASE_UTL = import.meta.env.VITE_BASE_URL

// 3. 创建路由实例并传递 `routes` 配置
// 你可以在这里输入更多的配置，但我们在这里
// 暂时保持简单
const router: any = createRouter({
    // 4. 内部提供了 history 模式的实现。为了简单起见，我们在这里使用 hash 模式。
    history: createWebHistory(BASE_UTL),
    routes: routes, // `routes: routes` 的缩写
    // scrollBehavior(to, from, savedPosition) {
    //     if (savedPosition) {
    //         return savedPosition
    //     } else {
    //         return { top: 0 }
    //     }
    // },
})

// 默认导出
export default router

